<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>把一个字符串压缩成 bzip2 编码数据</title>
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-base.css" />
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-medium.css" />

 </head>
 <body class="docs"><div class="navbar navbar-fixed-top">
  <div class="navbar-inner clearfix">
    <ul class="nav" style="width: 100%">
      <li style="float: left;"><a href="function.bzclose.html">« bzclose</a></li>
      <li style="float: right;"><a href="function.bzdecompress.html">bzdecompress »</a></li>
    </ul>
  </div>
</div>
<div id="breadcrumbs" class="clearfix">
  <ul class="breadcrumbs-container">
    <li><a href="index.html">PHP Manual</a></li>
    <li><a href="ref.bzip2.html">Bzip2 函数</a></li>
    <li>把一个字符串压缩成 bzip2 编码数据</li>
  </ul>
</div>
<div id="layout">
  <div id="layout-content"><div id="function.bzcompress" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">bzcompress</h1>
  <p class="verinfo">(PHP 4 &gt;= 4.0.4, PHP 5, PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">bzcompress</span> &mdash; <span class="dc-title">把一个字符串压缩成 bzip2 编码数据</span></p>

 </div>
 <div class="refsect1 description" id="refsect1-function.bzcompress-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>bzcompress</strong></span>(<span class="methodparam"><span class="type">string</span> <code class="parameter">$data</code></span>, <span class="methodparam"><span class="type">int</span> <code class="parameter">$block_size</code><span class="initializer"> = 4</span></span>, <span class="methodparam"><span class="type">int</span> <code class="parameter">$work_factor</code><span class="initializer"> = 0</span></span>): <span class="type"><span class="type">string</span>|<span class="type">int</span></span></div>

  <p class="para rdfs-comment">
   <span class="function"><strong>bzcompress()</strong></span> 压缩了指定的字符串并以 bzip2 编码返回数据。 
  </p>
 </div>

 <div class="refsect1 parameters" id="refsect1-function.bzcompress-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>
    
     <dt>
<code class="parameter">data</code></dt>

     <dd>

      <p class="para">
       待压缩的字符串。
      </p>
     </dd>

    
    
     <dt>
<code class="parameter">block_size</code></dt>

     <dd>

      <p class="para">
       指定压缩时使用的块大小，应该是一个 1-9 的数字。9 可以有最高的压缩比，但会使用更多的资源。
      </p>
     </dd>

    
    
     <dt>
<code class="parameter">work_factor</code></dt>

     <dd>

      <p class="para">
       控制压缩阶段出现最坏的重复性高的情况下输入数据时的行为。
       该值可以是在 0 至 250 之间，0是一个特殊的情况。
      </p>
      <p class="para">
       无论 <code class="parameter">work_factor</code>是什么，产生的输出都是一致的。
      </p>
     </dd>

    
   </dl>

  </p>
 </div>

 <div class="refsect1 returnvalues" id="refsect1-function.bzcompress-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   压缩后的字符串，或者在出现错误时返回错误号。
  </p>
 </div>

 <div class="refsect1 examples" id="refsect1-function.bzcompress-examples">
  <h3 class="title">范例</h3>
  <div class="example" id="example-704">
   <p><strong>示例 #1 压缩数据</strong></p>
   <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$str&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">"sample&nbsp;data"</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$bzstr&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">bzcompress</span><span style="color: #007700">(</span><span style="color: #0000BB">$str</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">9</span><span style="color: #007700">);<br />echo&nbsp;</span><span style="color: #0000BB">$bzstr</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
   </div>

   </div>
 </div>

 <div class="refsect1 seealso" id="refsect1-function.bzcompress-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"><span class="function"><a href="function.bzdecompress.html" class="function" rel="rdfs-seeAlso">bzdecompress()</a> - 解压经 bzip2 编码过的数据</span></li>
   </ul>
  </p>
 </div>

</div></div></div></body></html>